package com.heima.controller;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 接收对象
 */
@Component
public class HelloObjectListener {

    @KafkaListener(topics = {"user-topic"})
    public void receiverMessage(ConsumerRecord<String,String> record){
        Optional<? extends ConsumerRecord<String, String>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            String value = record.value();
            User user = JSON.parseObject( value, User.class);
            System.out.println("HelloObjectListener接收到消息="+user);
        }
    }
}